/*
** client.c 
directions to exectue client
1. compile using g++ client.c
2. execute using ./a.out
*/


#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <iostream>
#include <stdio.h>		
#include <sys/types.h>
#include <sys/socket.h> /* Definition of structures needed for sockets */
#include <netinet/in.h>
#include <sys/wait.h>
#include <netinet/in.h>	/* Definition of constants and structures for Internet Domain Addresses */
#include <sys/errno.h>
#include <sys/signal.h>
#include <string.h>
#include <values.h>
using namespace std;
// #define PORT "1000" // the port client will be connecting to

#define MAXDATASIZE 11000 // max number of bytes we can get at once

// get sockaddr, IPv4 or IPv6:

int main(int argc, char *argv[])
{
	int client_socket_fd, numbytes;
	char buf[MAXDATASIZE];
	char sender[MAXDATASIZE];
	struct sockaddr_in dest;
	
	//create first socket to connect to server
	/*---Open socket for streaming---*/
	if( (client_socket_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
	{
		perror("Socket");
		exit(errno);
	}

	/*---Initialize server address/port struct---*/
	//bzero(&dest, sizeof(dest));
	dest.sin_family = AF_INET;
	dest.sin_port = htons(5000);
	dest.sin_addr.s_addr = INADDR_ANY;

	/*---Connect to server---*/
	if(connect(client_socket_fd, (struct sockaddr*)&dest, sizeof(dest)) != 0 )
	{
		perror("Connect ");
		exit(errno);
	}
	printf("your are connected to the server");
	//gets comand so that it can connect to the other sockets
	//close(client_socket_fd);
	printf("\nplease enter message: ");
	cin >> buf;
		
	if(send(client_socket_fd, buf,100,0))
	{
		cout << "sent something";
	}
	//for if you recieve something from the Server	
	if(recv(client_socket_fd, buf,100,0))	// clinet gets the new port number
	{
		cout << buf;
	}
}
